package com.zqkey.rescuecommand.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.zqkey.rescuecommand.Assets;
import com.zqkey.rescuecommand.Game;
import com.zqkey.rescuecommand.OverlapTester;
import com.zqkey.rescuecommand.Settings;

public class StartScreen extends Screen {
	OrthographicCamera guiCam;
	SpriteBatch batcher;
	Vector3 touchPoint;
	Rectangle buttonNew;
	Rectangle buttonContinue;
	Rectangle buttonHelp;
	Rectangle buttonAbout;
	
	public StartScreen(Game game) {
		super(game);
		guiCam = new OrthographicCamera(Settings.gameWidth, Settings.gameHeight);
		guiCam.position.set(Settings.gameWidth / 2, Settings.gameHeight / 2, 0);
		batcher = new SpriteBatch();
		touchPoint = new Vector3();
		
		buttonNew = new Rectangle(480, 370, 256, 64);
		buttonContinue = new Rectangle(490, 280, 256, 64);
		buttonHelp = new Rectangle(490, 190, 256, 64);
		buttonAbout = new Rectangle(490, 100, 256, 64);
		Assets.playMusic(Assets.music);
	}

	@Override
	public void update(float deltaTime) {
		if (Gdx.input.justTouched()) {
			touchPoint.set(Gdx.input.getX(), Settings.gameHeight - Gdx.input.getY(), 0);
			
			if (OverlapTester.pointInRectangle(buttonNew, touchPoint.x, touchPoint.y)) {
				game.setScreen(new GameScreen(game));
				return;
			}
			if (OverlapTester.pointInRectangle(buttonContinue, touchPoint.x, touchPoint.y)) {
				if(!Assets.music.isPlaying()) {
					Assets.music.play();
				}
				return;
			}
			if (OverlapTester.pointInRectangle(buttonHelp, touchPoint.x, touchPoint.y)) {
				
				return;
			}
			if (OverlapTester.pointInRectangle(buttonAbout, touchPoint.x, touchPoint.y)) {
				return;
			}
//			game.setScreen(new GameScreen(game));
			return;
		}
	}

	@Override
	public void present(float deltaTime) {
		batcher.begin();
		batcher.draw(Assets.startRegion, 0, 0, Settings.gameWidth, Settings.gameHeight);
		batcher.draw(Assets.buttonNew, buttonNew.x, buttonNew.y, buttonNew.width, buttonNew.height);
		batcher.draw(Assets.buttonContinue, buttonContinue.x, buttonContinue.y, buttonContinue.width, buttonContinue.height);
		batcher.draw(Assets.buttonHelp, buttonHelp.x, buttonHelp.y, buttonHelp.width, buttonHelp.height);
		batcher.draw(Assets.buttonAbout, buttonAbout.x, buttonAbout.y, buttonAbout.width, buttonAbout.height);
		batcher.end();
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

}
